<html>
<head><meta charset="utf-8"><title>borrowed data escapes outside of function · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html">borrowed data escapes outside of function</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169083720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083720">(Jun 26 2019 at 21:49)</a>:</h4>
<p>I'm getting this error on a change I'm trying to do</p>



<a name="169083729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083729">(Jun 26 2019 at 21:49)</a>:</h4>
<div class="codehilite"><pre><span></span>error[E0521]: borrowed data escapes outside of function
   --&gt; src/librustc_codegen_ssa/mir/analyze.rs:228:9
    |
218 |     fn visit_place(&amp;mut self,
    |                    --------- `self` is declared here, outside of the function body
219 |                    place: &amp;mir::Place&lt;&#39;tcx&gt;,
    |                    ----- `place` is a reference that is only valid in the function body
...
228 |         self.process_place(place_ref, context, location);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `place` escapes the function body here

error: aborting due to previous error
</pre></div>



<a name="169083825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083825">(Jun 26 2019 at 21:50)</a>:</h4>
<p>place is a reference to <code>Place</code> that has <code>base</code> and <code>projection</code> fields</p>



<a name="169083846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083846">(Jun 26 2019 at 21:51)</a>:</h4>
<p>then I'm building a <code>PlaceRef</code> struct which is a different data structure that holds references to <code>base</code> and <code>projection</code> from <code>Place</code></p>



<a name="169083861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083861">(Jun 26 2019 at 21:51)</a>:</h4>
<p>I guess I should state that the references that <code>PlaceRef</code> hold do not outlive the reference to <code>Place</code></p>



<a name="169083928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083928">(Jun 26 2019 at 21:52)</a>:</h4>
<p>but unsure how to do it exactly</p>



<a name="169083944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083944">(Jun 26 2019 at 21:53)</a>:</h4>
<p>but also, I'm not understanding properly the error message</p>



<a name="169083951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169083951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169083951">(Jun 26 2019 at 21:53)</a>:</h4>
<p>/cc <span class="user-mention" data-user-id="124288">@oli</span></p>



<a name="169084094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169084094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169084094">(Jun 26 2019 at 21:55)</a>:</h4>
<p>just in case, this is the code ... <a href="https://github.com/rust-lang/rust/pull/60913/commits/2cf35e58d7eee9891784ca530e8639051d2c70ef" target="_blank" title="https://github.com/rust-lang/rust/pull/60913/commits/2cf35e58d7eee9891784ca530e8639051d2c70ef">https://github.com/rust-lang/rust/pull/60913/commits/2cf35e58d7eee9891784ca530e8639051d2c70ef</a></p>



<a name="169084757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169084757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169084757">(Jun 26 2019 at 22:04)</a>:</h4>
<p>ok, was doing a silly thing, fixed</p>



<a name="169084767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169084767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169084767">(Jun 26 2019 at 22:04)</a>:</h4>
<p>still the error message I think is not great</p>



<a name="169084790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169084790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169084790">(Jun 26 2019 at 22:05)</a>:</h4>
<p>/cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span> <span class="user-mention" data-user-id="124288">@oli</span> <span class="user-mention" data-user-id="119031">@Esteban Küber</span> opinions?</p>



<a name="169090664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169090664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169090664">(Jun 26 2019 at 23:38)</a>:</h4>
<p>At the very least the "outside of the function body" needs to be fixed in <a href="https://github.com/rust-lang/rust/blob/9606f6fa64926a84d82e3c62dbdc57f5c10f756d/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs#L498-L575" target="_blank" title="https://github.com/rust-lang/rust/blob/9606f6fa64926a84d82e3c62dbdc57f5c10f756d/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs#L498-L575">https://github.com/rust-lang/rust/blob/9606f6fa64926a84d82e3c62dbdc57f5c10f756d/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs#L498-L575</a></p>



<a name="169090679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169090679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169090679">(Jun 26 2019 at 23:39)</a>:</h4>
<p>but the error itself is not nice at all in this context</p>



<a name="169903109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169903109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169903109">(Jul 08 2019 at 20:42)</a>:</h4>
<p>yeah the error is pretty wildly inappropriate. not quite sure why that is happening.</p>



<a name="169903121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169903121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169903121">(Jul 08 2019 at 20:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> do you think you can file an issue with a minimal reproduction?</p>



<a name="169903131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169903131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169903131">(Jul 08 2019 at 20:42)</a>:</h4>
<p>maybe cc me and I'll try to add some notes at some point</p>



<a name="169909604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrowed%20data%20escapes%20outside%20of%20function/near/169909604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrowed.20data.20escapes.20outside.20of.20function.html#169909604">(Jul 08 2019 at 22:24)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> going to open an issue, yeah :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>